package com.jinbei.RestController;

import com.jinbei.cache.EhCacheService;
import com.jinbei.common.base.ResponseBase;
import com.jinbei.common.base.ResponseBaseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zflu
 * 活动课程 restful 接口
 * Created by lucky on 2018/8/8.
 */
@RestController
@RequestMapping("/course")
public class CourseController {

    private final Logger logger = LoggerFactory.getLogger(CourseController.class);

    @Autowired
    private EhCacheService ehCacheService;

    /**
     * @author zflu
     * @Description   根据类型查询活动课程信息
     * @date 2018/8/8 17:43
     * @param type
     * @return com.jinbei.common.base.ResponseBase
     */
    @GetMapping("/queryCourse")
    public ResponseBase queryCourse(@RequestParam("type") String type){
        try {
            Object cache = ehCacheService.getCache(type);
            return ResponseBaseEntity.setResultSuccess(cache);
        }catch (Exception e){
            logger.error("活动课程查询失败!  type:"+type,e);
            return ResponseBaseEntity.setResultError(null);
        }
    }

    /**
     * @author zflu
     * @Description   查询活动课程信息列表
     * @date 2018/8/8 17:43
     * @param
     * @return com.jinbei.common.base.ResponseBase
     */
    @GetMapping("/queryCourseList")
    public ResponseBase queryCourseList(){
        try {
            List<Object> cache = ehCacheService.getCacheAll();
            return ResponseBaseEntity.setResultSuccess(cache);
        }catch (Exception e){
            logger.error("活动课程列表查询失败!  ",e);
            return ResponseBaseEntity.setResultError(null);
        }
    }
}
